import api from '../../tool/requestModel.js'

function advertise() {
	const guangGaoWei = tt.createRewardedVideoAd({
		type: 100011056,
		unitId: 100011316,
	});
	return new Promise((resolve, rejects) => {
		if (!guangGaoWei) {
			return rejects({
				code: 203,
				msg: '该程序不支持广告'
			})
		}
		guangGaoWei.show()
			.catch(() => {
				guangGaoWei.load()
					.then(() => guangGaoWei.show())
					.catch(err => {
						tt.showToast({
							title: '激励视频广告显示失败',
							icon: 'none'
						})
						console.log('激励视频广告显示失败');
						rejects({
							code: 201,
							msg: err
						})
					});
			});
		guangGaoWei.onClose(({ isEnded }) => {
			if (isEnded) {
				// 给予奖励  // 跳转到答案页
				resolve({
					code: 200
				})
                
			} else {
				tt.showToast({
					title: '观看完广告才能查看结果哟',
					icon: 'none'
				})
				rejects({
					code: 202,
					msg: '观看完广告才能查看结果哟'
				})
			}
		});
        
        
	})
}

export default advertise
